package com.example.idlefish.PublicModule

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.idlefish.Message.MessageChatDAO
import com.example.idlefish.Message.MessageChatData

@Database(entities = [MessageChatData::class], version = 2, exportSchema = false)
abstract class IdleFishDatabase : RoomDatabase(){
    abstract fun messageChatDao(): MessageChatDAO

    companion object {
        @Volatile
        private var INSTANCE: IdleFishDatabase? = null

        fun getDatabase(context: Context): IdleFishDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    IdleFishDatabase::class.java,
                    "idle_fish_database"
                )
                    .fallbackToDestructiveMigration()
                    .build()
                INSTANCE = instance
                instance
            }
        }
    }
}